package com.sun.market;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import redis.clients.jedis.Jedis;

/**
 * 线程操作
 * 
 * @ClassName: MyRedistest
 * @author sunt
 * @date 2018年3月26日
 * @version V1.0
 */
public class MyRedistest {

	public static void main(String[] args) {
		final String WATCHKEYS = "watchkeys";
		ExecutorService executor = Executors.newFixedThreadPool(100); // 100个线程池并发数

		final Jedis jedis = new Jedis("127.0.0.1",6379);
		jedis.auth("123456");
		jedis.set(WATCHKEYS, "1000");// 初始化商品抢购的数量
		// jedis.del("setsucc", "setfail");
		jedis.close();
		for (int i = 0; i < 5000000; i++) {// 设置5000个人来发起抢购
			executor.execute(new MyRunnable("user" + getRandomString(6)));
		}
		executor.shutdown();
	}

	public static String getRandomString(int length) { // length是随机字符串长度
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}
	
	//public
}
